# ------------------------------------------------------------------------------
# Cargo Build Stage
# ------------------------------------------------------------------------------

FROM rust:latest as cargo-build

RUN  apt-get update && apt-get upgrade -y  \
     && apt-get install -y pkg-config build-essential libudev-dev musl-tools libssl-dev openssl

RUN rustup target add x86_64-unknown-linux-musl

WORKDIR /usr/src/myapp

COPY Cargo.toml Cargo.toml

RUN mkdir src/

#RUN echo "fn main() {println!(\"if you see this, the build broke\")}" > src/main.rs

#RUN RUSTFLAGS=-Clinker=musl-gcc cargo build --release --target=x86_64-unknown-linux-musl

#RUN rm -f target/x86_64-unknown-linux-musl/release/deps/myapp*

COPY . .

RUN RUSTFLAGS=-Clinker=musl-gcc cargo build --release --target=x86_64-unknown-linux-musl
#
## ------------------------------------------------------------------------------
## Final Stage
## ------------------------------------------------------------------------------
#
#FROM alpine:latest
#
#RUN addgroup -g 1000 myapp
#
#RUN adduser -D -s /bin/sh -u 1000 -G myapp myapp
#
#WORKDIR /home/myapp/bin/
#
#COPY --from=cargo-build /usr/src/myapp/target/x86_64-unknown-linux-musl/release/myapp .
#
#RUN chown myapp:myapp myapp
#
#USER myapp
#
#CMD ["./myapp"]